﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace GameSchoolApplication.Models
{
	public class Game
	{
        public Game()
        {
            this.IsOpen = false;
            this.Complete = false;
        }

		[Key]
		public int GameId { get; set; }
        
		[Display(Name = "Titill")]
		public string Title { get; set; }
        
		[Display(Name = "Lýsing")]
		public string Description { get; set; }
        
		[Display(Name = "Opinn?")]
        public bool IsOpen { get; set; }
        public bool Complete { get; set; }

		public int AuthorId { get; set; }
        
		[ForeignKey("AuthorId")]
        public virtual Person Author { get; set; }

		public virtual ICollection<Level>		   Levels		   { get; set; }
		public virtual ICollection<GameInstructor> GameInstructors { get; set; }
        public virtual ICollection<StudentPoints>  Enrollments	   { get; set; }
		public virtual ICollection<Announcement>   Announcements   { get; set; }
		public virtual ICollection<Notification>   Notifications    { get; set; }
        public IEnumerable<StudentAssignmentPoints> UngradedAssignments
        {
            get
            {
                return Enrollments.Where(e => e.Game.IsOpen).SelectMany(e => e.LevelEntries).SelectMany(le => le.AssignmentPoints).Where(ap => ap.Points == null);
            }
        }

        public IEnumerable<StudentTestPoints> UngradedTests
        {
            get
            {
                return Enrollments.Where(e => e.Game.IsOpen).SelectMany(e => e.LevelEntries).SelectMany(le => le.TestPoints).Where(tp => tp.Points == null);
            }
        }
	}
}